package com.emergency.embackend.config;

import com.emergency.embackend.interceptor.RefreshInterceptor;
import com.emergency.embackend.interceptor.LoginInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * @author chddd
 * @description
 * @create 2024/1/29 22:34:43
 */
@Slf4j
@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(new LoginInterceptor()).excludePathPatterns(
                "/user/code",
                "/user/login",
                "/user/register",

                "/sysUser/login",

                "/wiki/type/getWikiType",
                "/wiki/video/getVideo",
                "/wiki/video/getRecentVideo",
                "/wiki/video/getHotVideo",
                "/wiki/video/getOne",
                "/wiki/video/getRecommendVideo",
                "/wiki/article/getArticle",
                "/wiki/article/getRecentArticle",
                "/wiki/article/getOne",
                "/wiki/article/getRecommendArticle",

                "/quiz/type/getType",
                "/quiz/suit/page",
                "/quiz/suit/getRecentlySuit",
                "/quiz/history/getSort",
                "/testFirst/getByTypeId",

                "/help/hotByUpTime",
                "/share/pageTime",

                "/contentReturn/addContentReturn"
        ).order(1);
        registry.addInterceptor(new RefreshInterceptor(stringRedisTemplate)).addPathPatterns("/**").order(0);
    }
}
